Fix var keyword tokenization in tuple deconstruction at top level#356
Merged
Fix var keyword tokenization in tuple deconstruction at top level#356
Conversation
Co-authored-by: JoeRobich <611219+JoeRobich@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix var classification in tuple deconstruction
Add test coverage for var in tuple deconstruction with discards
Dec 20, 2025
JoeRobich
reviewed
Dec 20, 2025
Add local-tuple-declaration-deconstruction pattern to handle tuple deconstruction with type/var declarations like (int x, var y) = ... at the statement level. This fixes the issue where var was incorrectly tokenized as a variable name instead of a keyword when used in top-level tuple deconstruction. Co-authored-by: JoeRobich <611219+JoeRobich@users.noreply.github.com>
Copilot
AI
changed the title
Add test coverage for var in tuple deconstruction with discards
Fix var keyword tokenization in tuple deconstruction at top level
Dec 20, 2025
JoeRobich
approved these changes
Dec 20, 2025
dibarbet
approved these changes
Jan 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an issue where
varkeywords were not being correctly tokenized in tuple deconstruction patterns at the top level (outside of methods), causing them to appear as regular variables instead of type keywords.Problem
When using tuple deconstruction with
varkeywords at the top level:The
varkeywords were being tokenized asvariable.other.readwrite.cs(regular variables) instead ofstorage.type.var.cs(type keyword), preventing them from being highlighted correctly in the editor.Root Cause
The
local-tuple-var-deconstructionpattern only matchedvar (x, y) = ...syntax but not(var x, var y) = ...syntax at the statement level. When at the top level, the parenthesized expression pattern would match first and treatvaras an identifier.Solution
Added a new
local-tuple-declaration-deconstructionpattern to the grammar that:(type/var id, type/var id) = ...tuple-declaration-deconstruction-element-listto properly handlevarkeywordslocal-declarationso it's checked before general expression patternsChanges
local-tuple-declaration-deconstructionpattern insrc/csharp.tmLanguage.ymlInput.InMethodandInput.FromTextscenarios for:(int _, var _) = (1, 2);(var _, var _, var _) = ('a', 'b', 'c');All 897 tests pass. The
varkeyword is now correctly tokenized asstorage.type.var.csat both method and top levels.Original prompt
varin tuple deconstruction #316✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.